package threads;

import java.util.Arrays;

class Bank {
    private final double[] accounts;

    public Bank(int n, double initBalance) {
        this.accounts = new double[n];
        Arrays.fill(accounts, initBalance);
    }

    public void transfer(int from, int to, double amount) {
        if(accounts[from] < amount) return;

        accounts[from] -= amount;
        accounts[to] += amount;

        String thread = Thread.currentThread().getName();
        System.out.println(String.format("[%s] %.2f from %d to %d Total TotalBalance: %.2f", thread, amount, from, to, getTotalBalance()));
    }

    public double getTotalBalance(){
        double sum = 0;
        for(double b  : accounts){
            sum  += b;
        }
        return sum;
    }
}
